package com.ywgt.volatile_;

import java.util.concurrent.atomic.AtomicInteger;

public class JMMTest2 {
    private static AtomicInteger i=new AtomicInteger(0);

    public synchronized static void add(){
        i.incrementAndGet();
    }
    public static void main(String[] args) {
        for (int j = 0; j < 20; j++) {

            new Thread(()->{
                for (int k = 0; k < 1000; k++) {
                    add();
                }
            }).start();
        }

        while (Thread.activeCount()>2){
            Thread.yield();
        }
        System.out.println(i);
    }
}
